import { getSpots, getSpotById } from '@/api/spot';

const state = {
  spots: [],
  currentSpot: null,
};

const mutations = {
  SET_SPOTS(state, spots) {
    state.spots = spots;
  },
  SET_CURRENT_SPOT(state, spot) {
    state.currentSpot = spot;
  },
};

const actions = {
  fetchSpots({ commit }, params) {
    return getSpots(params).then(response => {
      commit('SET_SPOTS', response.data);
      return response.data;
    });
  },
  fetchSpotDetails({ commit }, id) {
    return getSpotById(id).then(response => {
      commit('SET_CURRENT_SPOT', response.data);
      return response.data;
    });
  },
};

const getters = {
  allSpots: state => state.spots,
  spotDetails: state => state.currentSpot,
};

export default {
  namespaced: true,
  state,
  mutations,
  actions,
  getters,
}; 